package demo1;

/**
 * @Author 12629
 * @Date 2022/4/2 19:12
 * @Description：
 */
class Animal {
    protected String name;
    private int age;

    static {
        System.out.println("Animal的静态代码块！");
    }

    {
        System.out.println("Animal的实例代码块！");
    }

   public Animal(String name, int age) {
        this.name = name;
        this.age = age;
       System.out.println("Animal带2个参数的构造方法");
    }

    public Animal() {
        System.out.println("Animal不带参数的构造方法");
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    public void eat() {
        System.out.println(this.name+" 正在吃饭！");
    }
}

class Cat extends Animal {

    public String hair;

    static {
        System.out.println("Cat的静态代码块！");
    }

    {
        System.out.println("Cat的实例代码块！");
    }

    public Cat() {
        super();
        System.out.println("Cat不带参数的构造方法");
    }

    public Cat(String name,int age,String hair) {
        super(name, age);//显示调用父类的构造方法，来初始化 子类从父类继承过来的东西
        this.hair = hair;
        System.out.println("Cat带3个参数的构造方法");
    }

    public void mew() {
        //System.out.println(this.name+" 正在叫！");//是不能访问了 不是没有被继承
        System.out.println(this.name +" 正在叫！");//是不能访问了 不是没有被继承
    }

    /*public static void testStatic() {
        System.out.println(super.getAge());不能再静态方法当中使用
    }*/
}


public class Test {

    protected int k = 99;

    public static void main(String[] args) {
        Cat cat1 = new Cat("咪咪",8,"black");

        System.out.println("=============");

        Cat cat2 = new Cat("咪咪",8,"black");

    }
    public static void mai1n(String[] args) {
        Cat cat1 = new Cat("咪咪",8,"black");
        cat1.mew();
        cat1.eat();
    }
}
